package org.cerberus.platform.client.impl;

import javax.swing.GroupLayout;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import org.cerberus.platform.client.ClientComponent;
import org.cerberus.platform.client.ClientContext;
import org.cerberus.platform.client.annotations.ClientClass;
import org.cerberus.platform.client.annotations.InjectClientContext;
import org.cerberus.platform.client.annotations.OnCreate;
import org.cerberus.platform.client.annotations.OnDispose;
import org.cerberus.platform.client.swing.bind.SwingBinding;

@ClientClass(classID="default.PAction")
public class MyClientClass extends JPanel {

	private JComboBox comboBox_1;
	private JComboBox comboBox;
	private JTextField textField_1;
	private JTextField textField;
	
	@InjectClientContext
	private ClientContext context;
	
	@OnCreate
	public void bind(ClientComponent component) {
		SwingBinding.bind(component, comboBox_1, component.getAttribute("availableCurrencies"));
		SwingBinding.bind(component, comboBox, component.getAttribute("availableCurrencies"));
		
		SwingBinding.bindSelected(component, comboBox_1, component.getAttribute("sourceCurrency"));
		SwingBinding.bindSelected(component, comboBox_1, component.getAttribute("targetCurrency"));
		
		SwingBinding.bind(component, textField_1, component.getAttribute("sourceAmount"));
		SwingBinding.bind(component, textField, component.getAttribute("targetAmount"));

	}
	
	@ClientEvent
	public Object takeSum() {
		return "anything";
	}
	
	
	@OnDispose
	public void unbind(ClientComponent component) {
		SwingBinding.removeBindings(this, component);
	}
	
	
	
	public MyClientClass() {
		super();

		JLabel sourceAmountLabel;
		sourceAmountLabel = new JLabel();
		sourceAmountLabel.setText("Source amount");

		JLabel targetAmountLabel;
		targetAmountLabel = new JLabel();
		targetAmountLabel.setText("target amount");

		textField = new JTextField();

		textField_1 = new JTextField();
		textField_1.setEditable(false);

		comboBox = new JComboBox();

		comboBox_1 = new JComboBox();
		final GroupLayout groupLayout = new GroupLayout((JComponent) this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addComponent(sourceAmountLabel)
						.addComponent(targetAmountLabel))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
						.addComponent(textField, GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
						.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(sourceAmountLabel)
						.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addComponent(targetAmountLabel)
						.addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(307, Short.MAX_VALUE))
		);
		setLayout(groupLayout);
	}
	
}
